/*
 * demuxer.c
 *
 *  Created on: Sep 4, 2009
 *      Author: tron
 */
#include <inttypes.h>
#include "WProgram.h"

#include "demuxer.h"

void demuxer_create(demuxer *d, uint8_t *pinArray, uint8_t inputs){
	d->input = pinArray;
	for (int i = 0; i<inputs; i++)
		pinMode(pinArray[i], OUTPUT);
}

void demuxer_setPin(const demuxer *d, uint8_t pin, uint8_t inputs){
	demuxer_strobeOn(d);
	for (uint8_t i = 0; i<inputs; i++)
		digitalWrite(*(d->input +i), ((pin>>i) & 0x01) ? HIGH:LOW);
	demuxer_strobeOff(d);
}

void demuxer_strobeOn(const demuxer *d){
	digitalWrite(d->strobe, HIGH);
}

void demuxer_strobeOff(const demuxer *d){
	digitalWrite(d->strobe, LOW);
}
